using System.Drawing;
using GTA;
using NativeUI;

namespace CustomPeds.Menus;

public class HeadOverlayMenu : Script
{
	public static UIMenu menu = new UIMenu("", TextSetting.ho_Menu, new Point(0, -107));

	private const int headOverlayStartIndex = 0;

	private const int headOverlayEndIndex = 12;

	private const int eyeIndex = 13;

	private const int hairIndex = 14;

	private static bool isMenuInitialized;

	public HeadOverlayMenu()
	{
		if (!isMenuInitialized)
		{
			Main.pool.Add(menu);
			menu.OnMenuClose += OnMenuClose;
			menu.OnItemSelect += OnItemSelect;
			isMenuInitialized = true;
		}
	}

	public static void InitHeadOverlayMenu()
	{
		menu.Clear();
		menu.SetBannerType(new UIResRectangle());
		menu.AddItem(new UIMenuItem(TextSetting.ho_MenuItem_Blemishes));
		menu.AddItem(new UIMenuItem(TextSetting.ho_MenuItem_Beard));
		menu.AddItem(new UIMenuItem(TextSetting.ho_MenuItem_Eyebrows));
		menu.AddItem(new UIMenuItem(TextSetting.ho_MenuItem_Ageing));
		menu.AddItem(new UIMenuItem(TextSetting.ho_MenuItem_Makeup));
		menu.AddItem(new UIMenuItem(TextSetting.ho_MenuItem_Blush));
		menu.AddItem(new UIMenuItem(TextSetting.ho_MenuItem_SunDamage));
		menu.AddItem(new UIMenuItem(TextSetting.ho_MenuItem_Skin));
		menu.AddItem(new UIMenuItem(TextSetting.ho_MenuItem_Lipstick));
		menu.AddItem(new UIMenuItem(TextSetting.ho_MenuItem_MolesFreckles));
		menu.AddItem(new UIMenuItem(TextSetting.ho_MenuItem_ChestHair));
		menu.AddItem(new UIMenuItem(TextSetting.ho_MenuItem_BodyBlemishes));
		menu.AddItem(new UIMenuItem(TextSetting.ho_MenuItem_DenseBodyBlemishes));
		for (int i = 0; i <= 12; i++)
		{
			menu.BindMenuToItem(HeadOverlaySubMenu.menu, menu.MenuItems[i]);
		}
		menu.AddItem(new UIMenuItem(TextSetting.ho_MenuItem_EyeColor));
		menu.AddItem(new UIMenuItem(TextSetting.ho_MenuItem_HairColor));
		menu.BindMenuToItem(OtherColorsSubMenu.menu, menu.MenuItems[13]);
		menu.BindMenuToItem(OtherColorsSubMenu.menu, menu.MenuItems[14]);
		menu.RefreshIndex();
	}

	private void OnItemSelect(UIMenu sender, UIMenuItem item, int index)
	{
		if (index >= 0 && index <= 12)
		{
			HeadOverlaySubMenu.InitHeadOverlaySubMenu(index);
		}
		if (index == 13)
		{
			OtherColorsSubMenu.InitOtherColorsSubMenu(OtherColorsSubMenu.OtherColors.Eye);
		}
		if (index == 14)
		{
			OtherColorsSubMenu.InitOtherColorsSubMenu(OtherColorsSubMenu.OtherColors.Hair);
		}
	}

	private void OnIndexChange(UIMenu sender, int index)
	{
	}

	private void OnMenuClose(UIMenu sender)
	{
		menu.Visible = false;
		menu.RefreshIndex();
	}
}
